<?php
/**
 * Created by PhpStorm
 * author: bxm
 * Date: 2023/3/10
 * Time: 10:47
 */

namespace app\api\controller\evaluation;

use app\admin\model\EvaluationElist;
use app\common\controller\ApiController;
use think\App;
header('Access-Control-Allow-Origin:*');
ini_set("max_execution_time", 300);
class Zhuiping  extends  ApiController
{
    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\EvaluationZhuiping();

    }
    /**
     * Notes: 追加评价
     * author: bxm
     * Date: 2023/2/20
     * Time: 16:51
     * @return mixed
     */
    public function zhuiping()
    {

        $row = [];
        if ($this->request->get()){
            $row['users_id'] = $_GET['users_id'];
            $row['template_id'] = $_GET['template_id'];
            $row['qr_user_id'] = $_GET['qr_user_id'];
        }
        if ($this->request->isPost()){
            $row['users_id'] = $_POST['users_id'];
            $row['template_id'] = $_POST['template_id'];
            $row['qr_user_id'] = $_POST['qr_user_id'];
        }

        if ($this->request->isPost()) {
            $post = $this->request->post();
            $rule = [];
            $this->validate($post, $rule);
            unset($post['qr_user_id']);
            try {
                $save = $this->model->save($post);
            } catch (\Exception $e) {
                $this->error('保存失败:'.$e->getMessage());
            }
            $save ? $this->success('感谢追加评价！') : $this->error('保存失败');
        }
        $this->assign('row',$row);
        return $this->fetch();
    }
    /**
     * 添加追评
     * @return void
     */
    public function addReview()
    {
        if ($this->request->isPost()) {
            $post = $this->request->post();

            $post['eva_id'] = EvaluationElist::where('qr_id',$post['qr_id'])->value('id');
            try {
                $save = $this->model->save($post);
            } catch (\Exception $e) {
                echo  json_encode(['code'=>1, 'msg'=> $e->getMessage()]);
            }

            $res = array('code' => '0', 'msg' => '感谢追加评价!', 'data' => $save);

            echo json_encode($res);
        }
    }
}